//
//  CJRelateVideTableViewCell.m
//  CoJellyCartoon
//
//  Created by dllo on 16/4/6.
//  Copyright © 2016年 CJG. All rights reserved.
//

#import "CJRelateVideTableViewCell.h"
@implementation CJRelateVideTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.videoPic = [[UIImageView alloc] initWithFrame:CGRectZero];
//        self.videoPic.backgroundColor = [UIColor yellowColor];
        [self addSubview:self.videoPic];
        
        self.titleLabe = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.titleLabe.font = [UIFont systemFontOfSize:14];
//        self.titleLabe.backgroundColor = [UIColor greenColor];
        self.titleLabe.numberOfLines = 2;
        [self addSubview:self.titleLabe];
        
        self.videoauthor = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.videoauthor.font = [UIFont systemFontOfSize:14];
        self.videoauthor.textColor = [UIColor lightGrayColor];
//        self.videoauthor.backgroundColor = [UIColor orangeColor];
        [self addSubview:self.videoauthor];
        
        self.videoPlayCountsPic = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.videoPlayCountsPic.image = [UIImage imageNamed:@"recplaycountpic"];
//        self.videoPlayCountsPic.backgroundColor = [UIColor greenColor];
        [self addSubview:self.videoPlayCountsPic];
        
        self.videoPlayCounts = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.videoPlayCounts.font = [UIFont systemFontOfSize:13];
        self.videoPlayCounts.textColor = [UIColor lightGrayColor];
//        self.videoPlayCounts.backgroundColor = [UIColor cyanColor];
        [self addSubview:self.videoPlayCounts];
        
        self.videoCommentsPic = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.videoCommentsPic.image = [UIImage imageNamed:@"pinglun"];
        [self addSubview:self.videoCommentsPic];
        
        self.videoComments = [[CJBaseLabel alloc] initWithFrame:CGRectZero];
        self.videoComments.font = [UIFont systemFontOfSize:15];
        self.videoComments.textColor = [UIColor lightGrayColor];
//        self.videoComments.backgroundColor = [UIColor redColor];
        [self addSubview:self.videoComments];
        
        
        
    }
    return self;
}
-(void)layoutSubviews{
    
    [super layoutSubviews]; 
    
    self.videoPic.frame = CGRectMake(5, 0, self.bounds.size.width/2.5, self.bounds.size.height-5);
    
    self.titleLabe.frame = CGRectMake(self.videoPic.bounds.origin.x +self.videoPic.bounds.size.width + 5, 0, self.bounds.size.width - self.bounds.size.width/2.5 - 5, 40);
    
    self.videoauthor.frame = CGRectMake(self.videoPic.bounds.origin.x +self.videoPic.bounds.size.width + 10, self.titleLabe.bounds.origin.y + self.titleLabe.bounds.size.height+5, 100, 20);
    
    self.videoPlayCountsPic.frame = CGRectMake(self.videoPic.bounds.origin.x +self.videoPic.bounds.size.width + 10, self.videoauthor.frame.origin.y + self.videoauthor.frame.size.height+5, 20, 20);
    
    self.videoPlayCounts.frame = CGRectMake(self.videoPic.bounds.origin.x +self.videoPic.bounds.size.width + 30, self.videoauthor.frame.origin.y + self.videoauthor.frame.size.height+5, 100, 20);
//    self.videoPlayCounts.frame = CGRectMake(self.videoPlayCountsPic.bounds.origin.x + self.videoPlayCountsPic.bounds.size.width + 5, self.videoauthor.frame.origin.y + self.videoauthor.frame.size.height + 5, 100, 20);
//
    self.videoCommentsPic.frame = CGRectMake(self.videoPic.bounds.origin.x +self.videoPic.bounds.size.width + 130, self.videoauthor.frame.origin.y + self.videoauthor.frame.size.height+5, 20, 20);
//
    self.videoComments.frame = CGRectMake(self.videoPic.bounds.origin.x +self.videoPic.bounds.size.width + 150, self.videoauthor.frame.origin.y + self.videoauthor.frame.size.height + 5, 100, 20);
    
}

-(void)setRelateModel:(CJRelatesModel *)relateModel{
    
    _relateModel = relateModel;
    [self.videoPic sd_setImageWithURL:[NSURL URLWithString:relateModel.pic] placeholderImage:[UIImage imageNamed:@"zhanweiye"]];
    
    self.titleLabe.text = relateModel.title;
    if (relateModel.stat[@"view"]) {
        
        NSNumber *viewCount = relateModel.stat[@"view"];
        
        if (viewCount.intValue > 10000) {
            self.videoPlayCounts.text = [NSString stringWithFormat:@"%d.%d万",(int)viewCount / 10000 , (int)viewCount%10000];
        }
    }
    self.videoPlayCounts.text = [NSString stringWithFormat:@"%@",relateModel.stat[@"view"]];
    self.videoComments.text = [NSString stringWithFormat:@"%@",relateModel.stat[@"danmaku"]];
    self.videoauthor.text = [NSString stringWithFormat:@"%@",relateModel.owner[@"name"]];
    
}
@end
